package com.mycompany.dao.hibernate;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.mycompany.dao.EventDao;
import com.mycompany.model.Event;

@Repository("eventDao")
public class EventDaoHibernate  extends GenericDaoHibernate<Event, Long> implements EventDao {

	public EventDaoHibernate() {
        super(Event.class);
    }
	
	public EventDaoHibernate(Class<Event> persistentClass) {
		super(persistentClass);
		// TODO Auto-generated constructor stub
	}

	public EventDaoHibernate(Class<Event> persistentClass,
			SessionFactory sessionFactory) {
		super(persistentClass, sessionFactory);
		// TODO Auto-generated constructor stub
	}


	public Event saveEvent(Event event) {
        getHibernateTemplate().saveOrUpdate(event);
        getHibernateTemplate().flush();
        
        return event;

	}

	@SuppressWarnings("unchecked")
	public List<Event> getEvents() {
		return getHibernateTemplate().find("from Event e order by upper(e.name)");
	}

	public Event getEvent(Long id) {
		return getHibernateTemplate().get(Event.class, id);
	}
	
	
	
	

}
